package com.sunlands.qdcy.tongzhuo.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.sunlands.qdcy.tongzhuo.model.UserDiaryReplyDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
import java.util.Objects;

/**
 * @date 2019/5/2914:21
 */
@Data
@JsonSerialize
@ApiModel(value = "评论详情信息")
@Builder
public class UserDiaryCommentVO {

    @Id
    @ApiModelProperty(value = "评论id")
    private Long id;

    @ApiModelProperty(value = "日记id")
    private Long diaryId;

    @ApiModelProperty(value = "评论用户id")
    private Long userId;

    @ApiModelProperty(position = 80, value = "身份(primary_and_middle_school 中小学| college_student 大学生| office_worker 上班族 |liberals 自由派)")
    private String identityName;

    @ApiModelProperty(value = "评论用户昵称")
    private String userName;

    @ApiModelProperty(value = "评论用户头像")
    private String userAvatarUrl;

    @ApiModelProperty(value = "当前学习目标")
    private String userCurrentLearnTargetName;

    @ApiModelProperty(value = "评论内容")
    private String commentContent;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty(value = "评论点赞数")
    private Integer zanCommentCount;

    @ApiModelProperty(value = "评论回复数")
    private Integer commentReplyCount;

    @ApiModelProperty(value = "是否是作者")
    private Boolean author;

    @ApiModelProperty(value = "是否赞过")
    private Boolean zan;

    @ApiModelProperty(value = "2:评论的回复，3:回复的回复")
    private Integer type;

    @ApiModelProperty(value = "回复列表")
    private Page<InnerDiaryReply> innerDiaryReplyListPage;

    @Data
    @JsonSerialize
    @ApiModel(value = "回复详情信息")
    @Builder
    public static class InnerDiaryReply {

        @Id
        @GeneratedValue
        @ApiModelProperty(value = "回复id")
        private Long id;

        @ApiModelProperty(value = "日记id")
        private Long diaryId;

        @ApiModelProperty(value = "评论id")
        private Long commentId;

        @ApiModelProperty(value = "回复用户id")
        private Long replyUserId;

        @ApiModelProperty(position = 80, value = "身份(primary_and_middle_school 中小学| college_student 大学生| office_worker 上班族 |liberals 自由派)")
        private String replyIdentity;

        @ApiModelProperty(value = "回复用户昵称")
        private String replyUserName;

        @ApiModelProperty(value = "回复用户头像")
        private String replyUserAvatarUrl;

        @ApiModelProperty(value = "回复内容")
        private String replyContent;

        @ApiModelProperty(value = "被回复的id")
        private Long replyedId;

        @ApiModelProperty(value = "被回复用户id")
        private Long replyedUserId;

        @ApiModelProperty(value = "回复用户昵称")
        private String replyedUserName;

        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        private Date createTime;

        @ApiModelProperty(value = "点赞数")
        private Integer zanCount;

        @ApiModelProperty(value = "回复用户目标名称")
        private String userCurrentLearnTargetName;

        @ApiModelProperty(value = "是否是作者")
        private Boolean author;

        @ApiModelProperty(value = "是否赞过")
        private Boolean zan;

        @ApiModelProperty(value = "2:评论的回复，3:回复的回复")
        private Integer type;

        @ApiModelProperty(value = "回复用户id, 冗余")
        private Long userId;

        @ApiModelProperty(position = 80, value = "身份(primary_and_middle_school 中小学| college_student 大学生| office_worker 上班族 |liberals 自由派), 冗余")
        private String identityName;

        @ApiModelProperty(value = "回复用户昵称, 冗余")
        private String userName;

        @ApiModelProperty(value = "回复用户头像, 冗余")
        private String userAvatarUrl;

        @ApiModelProperty(value = "回复内容, 冗余")
        private String commentContent;

        @ApiModelProperty(value = "点赞数,冗余")
        private Integer zanCommentCount;

        public static InnerDiaryReply from(UserDiaryReplyDO userDiaryReply) {
            return Objects.isNull(userDiaryReply) ? null : InnerDiaryReply.builder()
                    .id(userDiaryReply.getId())
                    .diaryId(userDiaryReply.getDiaryId())
                    .replyContent(userDiaryReply.getReplyContent())
                    .replyUserId(userDiaryReply.getReplyUserId())
                    .commentId(userDiaryReply.getCommentId())
                    .createTime(userDiaryReply.getCreateTime())
                    .replyedId(userDiaryReply.getReplyedId())
                    .replyedUserId(userDiaryReply.getReplyedUserId())
                    .type(userDiaryReply.getType())
                    .userId(userDiaryReply.getReplyUserId())
                    .commentContent(userDiaryReply.getReplyContent())
                    .build();
        }

    }

    public static UserDiaryCommentVO from(UserDiaryReplyDO userDiaryReply) {
        return Objects.isNull(userDiaryReply) ? null: UserDiaryCommentVO.builder()
                .id(userDiaryReply.getId())
                .diaryId(userDiaryReply.getDiaryId())
                .commentContent(userDiaryReply.getReplyContent())
                .userId(userDiaryReply.getReplyUserId())
                .createTime(userDiaryReply.getCreateTime())
                .updateTime(userDiaryReply.getUpdateTime())
                .type(userDiaryReply.getType())
                .build();
    }

}
